@model VotingSystem.ViewModels.SurveyCreateViewModel

@{
    ViewData["Title"] = "创建问卷";
}

<div class="container-fluid">
    <div class="row">
        <!-- 主要内容区域 -->
        <div class="col-md-9">
            <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
                <h1 class="h2">创建问卷</h1>
                <div class="btn-toolbar mb-2 mb-md-0">
                    <div class="btn-group me-2">
                        <button type="button" class="btn btn-outline-secondary" onclick="previewSurvey()">
                            <i class="fas fa-eye"></i> 预览
                        </button>
                        <button type="button" class="btn btn-primary" onclick="saveSurvey()">
                            <i class="fas fa-paper-plane"></i> 发布
                        </button>
                    </div>
                </div>
            </div>

            <form id="surveyForm" asp-action="Create" method="post">
                <div class="card mb-4">
                    <div class="card-body">
                        <div class="mb-3">
                            <label asp-for="Title" class="form-label">问卷标题</label>
                            <input asp-for="Title" class="form-control" required>
                            <span asp-validation-for="Title" class="text-danger"></span>
                        </div>
                        <div class="mb-3">
                            <label asp-for="Description" class="form-label">问卷说明</label>
                            <textarea asp-for="Description" class="form-control" rows="3" required></textarea>
                            <span asp-validation-for="Description" class="text-danger"></span>
                        </div>
                        <div class="row">
                            <div class="col-md-6">
                                <div class="mb-3">
                                    <label asp-for="EndTime" class="form-label">截止时间</label>
                                    <input asp-for="EndTime" class="form-control" type="datetime-local" value="@DateTime.Now.ToString("yyyy-MM-dd")T23:59" placeholder="年/月/日">
                                    <span asp-validation-for="EndTime" class="text-danger"></span>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-check mt-4">
                                    <input asp-for="IsAnonymous" class="form-check-input" type="checkbox">
                                    <label asp-for="IsAnonymous" class="form-check-label">匿名问卷</label>
                                </div>
                                <div class="form-group">
                                    <div class="form-check">
                                        <input asp-for="IsPublic" class="form-check-input" checked />
                                        <label asp-for="IsPublic" class="form-check-label">公开发布</label>
                                        <small class="form-text text-muted">勾选后所有人可见，不勾选则仅创建者可见。</small>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="form-check">
                                <input asp-for="AllowMultipleSubmissions" class="form-check-input" />
                                <label asp-for="AllowMultipleSubmissions" class="form-check-label">允许重复填写</label>
                            </div>
                        </div>
                    </div>
                </div>

                <div id="questionList">
                    <!-- 问题将通过JavaScript动态添加到这里 -->
                </div>
            </form>
        </div>

        <!-- 右侧工具栏 -->
        <div class="col-md-3">
            <div class="position-sticky" style="top: 2rem;">
                <div class="card">
                    <div class="card-header bg-primary text-white">
                        <h6 class="mb-0">添加题目</h6>
                    </div>
                    <div class="list-group list-group-flush">
                        <a href="#" class="list-group-item list-group-item-action d-flex align-items-center gap-2" onclick="addQuestion(0); return false;">
                            <i class="fas fa-dot-circle"></i> 单选题
                        </a>
                        <a href="#" class="list-group-item list-group-item-action d-flex align-items-center gap-2" onclick="addQuestion(1); return false;">
                            <i class="fas fa-check-square"></i> 多选题
                        </a>
                        <a href="#" class="list-group-item list-group-item-action d-flex align-items-center gap-2" onclick="addQuestion(2); return false;">
                            <i class="fas fa-paragraph"></i> 填空题
                        </a>
                        <a href="#" class="list-group-item list-group-item-action d-flex align-items-center gap-2" onclick="addQuestion(3); return false;">
                            <i class="fas fa-star"></i> 评分题
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 预览模态框 -->
<div class="modal fade" id="previewModal" tabindex="-1">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">问卷预览</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>
            <div class="modal-body" id="previewContent">
            </div>
        </div>
    </div>
</div>

@section Scripts {
    <script src="https://cdn.jsdelivr.net/npm/sortablejs@1.15.0/Sortable.min.js"></script>
    <script src="~/js/survey-create.js"></script>
    @{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
} 